package com.joker.userExam.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.joker.userExam.dao.repo.UserInfoRepo;
import com.joker.userExam.model.UserInfo;
import com.joker.userExam.service.IUserLogin;
import com.joker.userExam.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 李杰
 * @date 2021/4/14 - 22:43
 */
@Service
public class UserLoginImpl implements IUserLogin {

    @Resource
    UserInfoRepo userInfoRepo;


    @Override
    public ResultUtil login(UserInfo model) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("username", model.getUsername()).eq("password", model.getPassword());

        UserInfo user = userInfoRepo.getOne(queryWrapper);
        System.err.println("*****************");
        System.out.println(user);
        if (user != null) {
            return ResultUtil.ok("登录成功", user);
        } else {
            return ResultUtil.error("用户名或密码错误");
        }
    }

    @Override
    public ResultUtil updateUserInfo(UserInfo userInfo) {
        boolean res = userInfoRepo.updateById(userInfo);

        if (res) {
            return ResultUtil.ok("success");
        } else {
            return ResultUtil.error("error");
        }
    }

}

